<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<style>
    	td .layui-form-select {
	     margin-top: -10px;
	     margin-left: -15px;
	     margin-right: -15px;
     }
     .layui-table tr th,td{white-space:nowrap;padding:5px;text-align:center;width:33.4%;};
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-card">
            <div class="layui-card-header">设备检修</div>
            <div class="layui-card-body">
              <div class="layui-tab" lay-filter="tab-all">
                <ul class="layui-tab-title" id="html_title">
                </ul>
                <div class="layui-tab-content" id="html_content">
                </div>
              </div>
            </div>
        </div>
        <div id="Myloading"><img src="../../lib/layui-v2.5.5/css/modules/layer/default/loading-01.gif" alt=""></div>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add"> 新增 </button>
            </div>
        </script>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit"   data-title="设备列表"  lay-event="edit">查看</a>
            <a class="layui-btn layui-btn-xs data-count-edit layui-btn-danger"   lay-event="delete">删除</a>
        </script>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['element', 'table','miniTab'], function () {
        // 2020-03-25 HF 保存token
        var token = sessionStorage.getItem('newtoken');
        var examine_type = sessionStorage.getItem('HsaveExamine_type');
        var examine_code = sessionStorage.getItem('HsaveExamine_code');

        var $ = layui.jquery,
            ele = layui.element,
            miniTab = layui.miniTab,
            table = layui.table;
            miniTab.listen();

            var html_title = '';
            var html_content = '';

// 获取头表  类型
            $.ajax({          
                    url: '/oms-web/examines/'+examine_type+'/reports/authority?token='+ token,
                    dataType:"json",  
                    type:"get", 
                    contentType:"application/json",
                        success:function(data){ if (data.code == -1) {
                          window.location = '../login-1.html'
                      }
                        if(data.code === 0){
                            $.each(data.data,function(index,alarmName){
                                html_title += '<li>'+alarmName+'</li>';
                                html_content += '<div class="layui-tab-item"><table class="layui-hide" id="HcurrentTableId" lay-filter="currentTableFilter"></table><div>'
                               });
                               $("#html_title").html(html_title);
                               $("#html_content").html(html_content);
                               
                              //  默认显示第一个tab
                              $("#html_title").children(":first").addClass('layui-this');
                              $("#html_content").children(":first").addClass('layui-show');

                              setTimeout(function(){
                                var reportName = $('#html_title').children(":first").text();
                console.log(reportName);
                                sessionStorage.setItem('report_Name',reportName)
                                examine_content(reportName);
                              },10)
                        }else{
                            layer.msg(data.msg,{icon: 1,time:1000});
                        }
                },
                    error:function () {
                        layer.msg("数据请求错误！");
                    }
            });

// 根据表头  切换表格
            ele.on('tab(tab-all)',function(data){
                var reportName = $(this).text();
                sessionStorage.setItem('report_Name',reportName)
                 layer.load(2)
                examine_content(reportName)
            })

// 表格
            function examine_content(reportName){
                        table.render({
                            elem: '#HcurrentTableId',
                            url: '/oms-web/examines/'+examine_type+'/'+examine_code+'/'+reportName+'/list/authority?token='+ token,
                            toolbar: '#toolbarDemo',  
                            parseData: function(res){ //res 即为原始返回的数据
                                    return {
                                    "code": res.code, //解析接口状态
                                    "msg": res.msg, //解析提示文本
                                    "count": res.data.total, //解析数据长度
                                    "data": res.data.list //解析数据列表
                                }},
                            defaultToolbar: ['filter', 'exports', 'print', {
                                title: '提示',
                                layEvent: 'LAYTABLE_TIPS',
                                icon: 'layui-icon-tips'
                            }],
                            
                            cols: [[
                                //复选框 {type: "checkbox", width: 50, fixed: "left"},
                                {type: 'numbers', width: 120, title: '序号', align: "center"},
                                {field: 'datetime', width: 300, title: '时间', align: "center"},
                                {field: 'experimenter', width: 300, title: '检修人员', align: "center"},
                                {field: 'auditors', title: '审核人员', width: 300, align: 'center'},
                                {title: '操作', width: 200, templet: '#currentTableBar',  align: "center"}
                            ]],
                            limits: [10, 15, 20, 25, 50, 100],
                            limit: 15,
                            page: true,
                            done:function(res){
                                if (res.code == -1) {
                    window.location = '../login-1.html';
                }
                                // 表格渲染完成回调
                                $('#Myloading').remove();
                                layer.closeAll();
                            }
                        });  
                 }
           
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {  
            console.log(obj);
            // 保存名字  用作URl
            var url =  obj.config.url; 
            sessionStorage.setItem('HsaveExamine_url',url.split('/')[5])
            if (obj.event === 'add') {  // 监听添加操作
                          layer.open({
                                title: '新增配置',
                                type: 2,
                                shade: 0.2,
                                maxmin:true,
                                shadeClose: true,
                                area: ['100%', '100%'],
                                content: './examine_add.html',
                            });
                    }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
        });

        // 获取列表data
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'edit') {  
            sessionStorage.setItem('HsaveBig_check',JSON.stringify(obj.data));
                layer.open({
                                title: '更新修改',
                                type: 2,
                                shade: 0.2,
                                maxmin:true,
                                shadeClose: true,
                                area: ['100%', '100%'],
                                content: './examine_update.html',
                            });   
            }else if(obj.event === 'delete'){
                var str = obj.data;
                layer.confirm('确定删除该数据并不可恢复！', {
                        btn: ['确定','取消'] //按钮
                        }, function(){
                        $.ajax({          
                                url: '/oms-web/examines/'+str.deviceType+'/'+str.deviceCode+'/'+str.reportName+'/'+str.recordNo+'/authority?token='+ token,
                                    dataType:"json",  
                                    type:"DELETE", 
                                    contentType:"application/json",
                                        success:function(data){ if (data.code == -1) {
                          window.location = '../login-1.html'
                      }
                                        if(data.code === 0){
                                            layer.msg(data.msg,{icon: 1,time:1000},function(){
                                                window.location.reload();//修改成功后刷新父界面
                                            });
                                        }else{
                                            layer.msg(data.msg,{icon: 1,time:1000});
                                        }
                                },
                                    error:function () {
                                        layer.msg("数据请求错误！");
                                    }
                            });
                  });
            }
        });

    });


</script>


</body>
</html>